package chapter_Thread_Ticket;

public class Ticket implements Runnable{
        private int count = 10;
		private int num = 0;
		private boolean saleoff = false;
		
		public void run() {
			while(!saleoff) {
				sale();
				
				String name = Thread.currentThread().getName();
				
				if(name.equals("黄牛党")) {
					break;
				}

			}
		}
		
	public synchronized void sale() {
		if(count<=0) {
			saleoff = true;
			return;
		}
		
		num++;
		count--;
		
		try {
			Thread.sleep(500);
		}catch(InterruptedException e) {
			e.printStackTrace();
		}
		
				
		System.out.println(Thread.currentThread().getName()+"抢到第"+num+"张票，剩余"+count+"张票！");
		
	}
	

}
